import {Component, OnInit, Input, Injector} from '@angular/core';
import { RecruitmentPlan} from '../../../domains/recruitmentplan.domain';
import {CoreComponent, Dynamic, TabView} from 'pengesoft-ng-lib';
import {RecruitmentPlanMgeSvrService} from '../../../services/recruitment-plan-mge-svr.service';


@Component({
  selector: 'app-recruitment-info',
  templateUrl: './recruitment-info.component.html',
  styleUrls: ['./recruitment-info.component.less']
})

@TabView('分组')
@Dynamic()
export class RecruitmentInfoComponent extends CoreComponent implements OnInit {
  @Input() info: any;
  isVisible = false;    // 控制弹框
  Info: RecruitmentPlan;  // 申请信息记录
  Remark: string;    // 驳回理由记录
  constructor(private injector: Injector,
              public recruSrv: RecruitmentPlanMgeSvrService) {
    super(injector);
  }

  ngOnInit(): void {
  }

  // 通过操作
  pass(n, info): void{
    info.RecruitmentPlan.CheckStatus = n;
    this.recruSrv.updateRecruitment(new RecruitmentPlan(info.RecruitmentPlan)).then( res => {
      if (res === 200){
        this.nzMessageSvr.success('审核成功');
      } else{
        this.nzMessageSvr.error('审核失败');
      }
    }, err => {
      this.nzMessageSvr.error(err.Msg);
    });
  }

  // 驳回操作
  nopass(info): void{
    this.isVisible = true;
    this.Info = info.RecruitmentPlan;
  }

  // 弹框相关

  handleOk(): void {
    this.Info.CheckStatus = 2;
    this.Info.Remark = this.Remark;
    this.recruSrv.updateRecruitment(new RecruitmentPlan(this.Info)).then( res => {
    }, err => {
      this.nzMessageSvr.error(err.Msg);
    });
    this.isVisible = false;
  }

  handleCancel(): void {
    this.isVisible = false;
  }
}
